package toolNet
{
	
	import com.cjson.CJSON;
	
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import newx.utils.debug.IO;

	public class Service
	{
		private var _conn		:		Connection;
		
		/**消息数组**/
		private var _logArr	:		Array = [];
		private var _timer		:		Timer;
		
		/**一次发送消息的条数**/
		private static var MSG_COUNTS:int = 10;
		public function Service(conn : Connection)
		{
			_timer = new Timer(100);
			_timer.addEventListener(TimerEvent.TIMER,timeHandle);
//			_timer.start();
			
			_conn	=	conn;
			
			IO.io.toolFunc	=	gameLog;
		}
		
		private function timeHandle(e:TimerEvent):void
		{
			if(_logArr.length<=0)
				return;
			_conn.send(CustomToToolFlag.DEBUG_LOG,_logArr);
			_logArr = [];
		}
		
		/**
		 *	发送游戏日志信息 
		 * @param log	日志信息
		 * 
		 */
		public function gameLog(log : Object):void
		{
//			_conn.send(CustomToToolFlag.DEBUG_LOG, log);
			if(CJSON.encode(_logArr).length>2000)
			{
				_conn.send(CustomToToolFlag.DEBUG_LOG,_logArr);
				_logArr = [];
			}else
			{
				_logArr.push(log);
			}
			
			
		}

		/**
		 * 	发送玩家信息
		 * @param role	玩家信息
		 * 
		 */
		public function roleData(role : Object):void
		{
			_conn.send(CustomToToolFlag.GAME_ROLE, role);
		}
		
		/**
		 * 	发送玩家信息
		 * @param role	玩家信息
		 * 
		 */
		public function roleGMData(role : Object):void
		{
			_conn.send(CustomToToolFlag.GAmE_ROLE_GM, role);
		}
		
		/**
		 *	发送场景数据 
		 * @param scene	场景信息
		 * 
		 */
		public function sceneData(scene : Object):void
		{
			_conn.sendScene(CustomToToolFlag.GAME_SCENE, scene);
		}
		
		/**
		 *	发送辅助信息 
		 * @param aide	
		 * 
		 */
		public function aideInfo(aide : Object):void
		{
			_conn.send(CustomToToolFlag.AIDE_INFO, aide);

		}
	}
}